var totalPage = 0
var totalCount = 0
var pageSize = 10
var currentPage = 1

//复核 查询单个
function fuhechaxundange(trainId) {

    location.href = "/培训复核?trainId=" + trainId

}

//反馈
function fankuichaxundange(trainId) {

    location.href = "/培训反馈?trainId=" + trainId

}

//修改
function upd(trianId) {
    location.href = "/培训修改?trainId=" + trianId
}

function updboacun() {
    let trainId = $("#trainId").val()
    let name = $(".name").val()
    let teacher = $(".teacher").val()
    let startTime = $(".startTime").val()
    let endTime = $(".endTime").val()
    let people = $(".people").val()
    let goal = $(".goal").val()
    let introduction = $(".introduction").val()
    let data = $(".data").val()


    let jsonA = {
        "trainId": trainId,
        "name": name,
        "teacher": teacher,
        "startTimes": startTime,
        "endTimes": endTime,
        "people": people,
        "goal": goal,
        "introduction": introduction,
        "data": data,
        "status": "审核中"
    }
    console.log(jsonA)

    $.ajaxSettings.async = false
    $.getJSON("train/updbaocun", jsonA, function (dataA) {

        if (dataA == true) {
            alert("审核中。。。。")
            location.href = "/培训计划"
        } else {
            alert("审核失败")
        }
    }, "json")
    $.ajaxSettings.async = true

}


//反馈保存
function FKupd() {
    let trainId = $("#trainId").val()
    let back = $("#back option:selected").val()
    let sumUp = $("#sumUp").val()
    let result = $("#result").val()
    if (back == "" || sumUp == "" || result == "") {
        alert("请完善信息")
        return
    }
    let jsonA = {
        "trainId": trainId,
        "back": back,
        "sumUp": sumUp,
        "result": result
    }

    $.ajaxSettings.async = false
    $.getJSON("train/fankuibaocun", jsonA, function (dataA) {
        if (dataA == true) {
            alert("保存成功")
            location.href = "/培训计划"
        } else {
            alert("保存失败")
        }

    }, "json")

}


//审核中
$(function () {
    $("#btnss2").click(function () {
        // let name = $(".name").val()
        // let teacher = $(".teacher").val()
        // let startTime = $(".startTime").val()
        // let endTime = $(".endTime").val()
        // let people = $(".people").val()
        // let goal = $(".goal").val()
        // let introduction = $(".introduction").val()
        // let data = $(".data").val()


        let file = $("#file").val().trim();
        console.log("==================="+file)

        // if(reName1==''|| reSex=='请选择' || reType=='请选择'|| email==''|| phone==''||peraddress==''||
        //     address==''||politicsID=='请选择'||statusID==''|| SchoolTag==''|| education==''|| payRequire==''||
        //     noJob=='请选择'||graduate=='请选择'||major==''||workEx==''||checkTime==''||resume1==''||
        //     isRecommend=='请选择'||resState=='请选择'|| file==''){
        //     alert("请填写正确格式！");
        //     return false;
        // }



        var formData = new FormData($('#duowenjian')[0]);
        $.ajax({
            type: 'post',
            url: "/train/add2",
            data: formData,
            cache: false,

            processData: false,
            contentType: false,
            success:function (dataA) {
                // alert("添加成功")
                // location.href="/培训计划"
                if (dataA=="true"){
                    alert("审核中。。。")
                    location.href="/培训计划"
                }else{
                    alert("审核失败")

                }

            }
        })
    });
});


//添加 申乾航
$(function () {
    $("#btnss").click(function () {
      let name = $(".name").val()
      let teacher = $(".teacher").val()
      let startTime = $(".startTime").val()
      let endTime = $(".endTime").val()
      let people = $(".people").val()
      let goal = $(".goal").val()
      let introduction = $(".introduction").val()
      let data = $(".data").val()

        if (startTime>endTime){
            alert("请添加正确时间")
            return
        }


        let file = $("#file").val().trim();
        console.log("==================="+file)

        // if(reName1==''|| reSex=='请选择' || reType=='请选择'|| email==''|| phone==''||peraddress==''||
        //     address==''||politicsID=='请选择'||statusID==''|| SchoolTag==''|| education==''|| payRequire==''||
        //     noJob=='请选择'||graduate=='请选择'||major==''||workEx==''||checkTime==''||resume1==''||
        //     isRecommend=='请选择'||resState=='请选择'|| file==''){
        //     alert("请填写正确格式！");
        //     return false;
        // }



        var formData = new FormData($('#duowenjian')[0]);
        $.ajax({
            type: 'post',
            url: "/train/add1",
            data: formData,
            cache: false,

            processData: false,
            contentType: false,
            success:function (dataA) {
                // alert("添加成功")
                // location.href="/培训计划"
                if (dataA=="true"){
                     alert("添加成功")
                     location.href="/培训计划"
                }else{
                    alert("添加失败")

                }

            }
        })
    });
});

// //起草
// function add1() {
//
//     let name = $(".name").val()
//     let teacher = $(".teacher").val()
//     let startTime = $(".startTime").val()
//     let endTime = $(".endTime").val()
//     let people = $(".people").val()
//     let goal = $(".goal").val()
//     let introduction = $(".introduction").val()
//     let data = $(".data").val()
//
//     if (name == "" || teacher == "" ||
//         startTime == "" || endTime == ""
//         || people == "" || goal == "" ||
//         introduction == "" || data == "") {
//         alert("请完善信息")
//         location.reload()
//     }
//
//     var formData = new FormData($('#wenjianshangchuan')[0]);
//
//     let jsonA = {
//         "name": name,
//         "teacher": teacher,
//         "startTimes": startTime,
//         "endTimes": endTime,
//         "people": people,
//         "goal": goal,
//         "introduction": introduction,
//          "data": data,
//
//         data: formData,
//         cache: false,
//
//
//         processData: false,
//         contentType: false
//
//
//     }
//     console.log(jsonA)
//     $.ajaxSettings.async = false
//     $.getJSON("/train/add1", jsonA, function (dataA) {
//
//
//         if (dataA == true) {
//             alert("保存成功")
//             location.href = "/培训计划"
//         } else {
//             alert("保存失败")
//             location.href = "/培训计划"
//         }
//     }, 'json')
//
//     $.ajaxSettings.async = true
//
// }

//申请复核
function add2() {
    let name = $(".name").val()
    let teacher = $(".teacher").val()
    let startTime = $(".startTime").val()
    let endTime = $(".endTime").val()
    let people = $(".people").val()
    let goal = $(".goal").val()
    let introduction = $(".introduction").val()
    let data = $(".data").val()

    if (name == "" || teacher == "" ||
        startTime == "" || endTime == ""
        || people == "" || goal == "" ||
        introduction == "" || data == "") {
        alert("请完善信息")
        location.reload()
    }

    let jsonA = {
        "name": name,
        "teacher": teacher,
        "startTimes": startTime,
        "endTimes": endTime,
        "people": people,
        "goal": goal,
        "introduction": introduction,
        "data": data
    }
    console.log(jsonA)
    $.ajaxSettings.async = false
    $.getJSON("/train/add2", jsonA, function (dataA) {

        if (dataA == true) {
            alert("复核中。。。。")
            location.href = "/培训计划"
        } else {
            alert("复核失败")
            location.href = "/培训计划"
        }
    }, 'json')

    $.ajaxSettings.async = true

}

//驳回
function bohui() {
    let trainId = $("#trainId").val()
    let opinion = $("#opinion").val()
    if (opinion == "" || opinion == null) {
        alert("请完善信息")
        return
    }

    console.log("意见为" + opinion)
    console.log(trainId + "================================")
    let jsonA = {
        "trainId": trainId,
        "opinion": opinion
    }
    console.log("json为" + jsonA)
    $.ajaxSettings.async = false
    $.getJSON("/train/bohui", jsonA, function (dataA) {

        if (dataA == true) {
            alert("已驳回")
            location.href = "培训计划"
        } else {
            alert("驳回失败")
            location.href = "培训计划"
        }
    })
    $.ajaxSettings.async = true


}

//通过
function tongguo() {
    let trainId = $("#trainId").val()
    let opinion = $("#opinion").val()
    if (opinion == "") {
        alert("请完善信息")
        return
    }

    console.log("意见为" + opinion)
    console.log(trainId + "================================")
    let jsonA = {
        "trainId": trainId,
        "opinion": opinion
    }
    console.log("json为" + jsonA)
    $.ajaxSettings.async = false
    $.getJSON("/train/tongguo", jsonA, function (dataA) {

        if (dataA == true) {
            alert("已通过")
            location.href = "培训计划"
        } else {
            alert("通过失败")
            location.href = "培训计划"
        }
    })
    $.ajaxSettings.async = true

}

//查询
function showData() {

    $(".show1 tr:gt(0) td").html("&nbsp;");


    $.ajaxSettings.async = false
    $.post("/train/sel", "", function (dataA) {

        $(dataA).each(function (i, v) {
            let str = ''
            if (v.status == '起草') {
                str = '<a href="#">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">申请复核</a>'
            } else if (v.status == '审核中') {
                str = '<a href="#">申请复核</a>'
            } else {
                str = '<a href="#">培训反馈</a>'
            }
            $(".show1").find("tr").eq(i + 1).find("td").eq(0).text((currentPage-1)*pageSize+i+1)
            $(".show1").find("tr").eq(i + 1).find("td").eq(1).text(v.name)
            $(".show1").find("tr").eq(i + 1).find("td").eq(2).text(v.teacher)
            $(".show1").find("tr").eq(i + 1).find("td").eq(3).text(v.startTime)
            $(".show1").find("tr").eq(i + 1).find("td").eq(4).text(v.back)
            $(".show1").find("tr").eq(i + 1).find("td").eq(5).text(v.status)
            $(".show1").find("tr").eq(i + 1).find("td").eq(6).html(str)

        })
    }, 'json')
    $.ajaxSettings.async = true
}

//模糊分页查询
function showData2() {
    $(".show1 tr:gt(0) td").html("&nbsp;")

    let trainId = $(".trianId").val()
    let name = $(".name").val().trim()
    let status = $(".status option:selected").val().trim()
    let startTime = $(".startTime").val().trim()
    // alert(name)
    let jsonA = {

        "name": name,
        "status": status,
        "startTime": startTime,
        "currentPage": currentPage,
        "pageSize": pageSize
    }
    console.log(jsonA)
    $.ajaxSettings.async = false
    $.getJSON("/train/trainMoFenSel", jsonA, function (dataA) {


        console.log(dataA)
        totalPage = dataA.pages
        totalCount = dataA.total


        $(dataA.list).each(function (i, v) {


            let str = ''
            if (v.status == '起草') {
                // str = '<a href="javascript:void(0)" onclick="upd(' + v.trainId + ')">修改</a>'
                str = '<button class="layui-btn layui-btn-sm"><a href="javascript:void(0)"  style="color: white" onclick="upd(' + v.trainId + ')">修改</a></button>'
                // &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)">复核</a>
            } else if (v.status == '审核中') {
                str = '<button class="layui-btn layui-btn-sm"><a href="javascript:void(0)"  style="color: white" onclick="fuhechaxundange(' + v.trainId + ')">复核</a></button>'
            } else if (v.status == "通过") {
                str = '<button class="layui-btn layui-btn-sm"><a href="javascript:void(0)"  style="color: white" onclick="fankuichaxundange(' + v.trainId + ')">培训反馈</a></button>'
            }
            else if(v.status=="驳回"){
                str = '<button class="layui-btn layui-btn-sm">已驳回</button>'
            }
            $(".show1").find("tr").eq(i + 1).find("td").eq(0).text((currentPage-1)*pageSize+i+1)
            $(".show1").find("tr").eq(i + 1).find("td").eq(1).text(v.name)
            $(".show1").find("tr").eq(i + 1).find("td").eq(2).text(v.teacher)
            $(".show1").find("tr").eq(i + 1).find("td").eq(3).text(v.startTime)
            $(".show1").find("tr").eq(i + 1).find("td").eq(4).text(v.back)
            $(".show1").find("tr").eq(i + 1).find("td").eq(5).text(v.status)
            $(".show1").find("tr").eq(i + 1).find("td").eq(6).html(str)

        })


    }, "json")
    $.ajaxSettings.async = true;

    showPage()

}

//展示页码
function showPage() {
    $(".page").text(currentPage + "/" + totalPage)
}

// 上一页
function prv() {
    currentPage--;
    if (currentPage < 1) {
        currentPage = 1;
        return;
    }
    showData2();
}

// 首页
function first() {
    currentPage = 1
    showData2();
}

// 尾页
function last() {
    currentPage = totalPage;
    showData2();
}


function next() {
    currentPage++;
    if (currentPage > totalPage) {
        currentPage = totalPage;
        return;
    }
    showData2();
}

//模糊查询
function selPro() {
    // //防止出现2/1的情况
    currentPage = 1;


    //分页查询数据
    showData2();
    // //以下判断防止“0数据”，出现1/0的情况出现
    if (totalCount == 0) {
        alert("没有找到数据")
        totalPage = 1;
        $(".page").text(currentPage + "/" + totalPage);

    }

}

